/**
 * @author hewei
 * @version 1.0
 * @description: TODO
 * @date 2022/10/30 15:34
 */

public class MinMoves3 {

    public int minMoves(int[] nums, int limit) {
        int temp = limit * 2;
        int[] delta = new int[temp + 2];
        int n = nums.length;
        for (int i = 0; i < n / 2; i++) {
            int a = nums[i];
            int b = nums[n - 1 - i];
            delta[2] += 2;
            delta[Math.min(a, b) + 1]--;
            delta[Math.max(a, b) + limit + 1]++;
            delta[a + b]--;
            delta[a + b + 1]++;
        }
        int ans = delta[2];
        int sum = delta[2];
        for (int i = 3; i <= temp; i++) {
            sum += delta[i];
            ans = Math.min(ans, sum);
        }
        return ans;
    }
}
